package com.fqh.controller;

import com.fqh.config.URLconfig;
import com.fqh.entity.InfoGroup;
import com.fqh.entity.JsonResult;
import com.fqh.entity.Order1;
import com.fqh.entity.Orderinfo;
import com.fqh.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("findAllOrder.do")
    private Map<String, Object> findAllOrder(int page, int limit) {
        List<Order1> list = orderService.findAllOrder(page, limit);
        Integer count = orderService.findCount();
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("data", list);
        map.put("count", count);
        return map;
    }

    @RequestMapping("deleteById1.do")
    private JsonResult deleteById(Integer id) {
        JsonResult result = null;
        try {
            orderService.deleteById(id);
            result = new JsonResult("删除成功", true);
        } catch (Exception e) {
            result = new JsonResult("删除失败", false);
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("orderInfo.do")
    public List orderInfo(@RequestParam("orderNum") String orderNum) {
        List<InfoGroup> list = orderService.orderInfo(orderNum);
        return list;
    }
}
